#"""
#创建数据库或数据模型更改后，立即进行下列操作  2022.11.30
# 1、重新创建数据库 E:\python\UDP\mysite
# del E:\python\UDP\mysite\blog\migrations\0001_initial.py
# del E:\python\UDP\mysite\db.sqlite3 
# python manage.py makemigrations blog
# python manage.py migrate
# python manage.py runserver 192.168.3.142:8080
# 2、或者：
# C:\Documents and Settings\Administrator>djDB_UserInfo_Msg_8080.bat
#"""

from django.db import models
from django.contrib import admin

#用户
class UserInfo(models.Model):
    macAddress = models.CharField(max_length=20,  default="70720d06e84b", primary_key=True)  #mac，主键是防止重复写入的 
    name = models.CharField(max_length=20,  default="随缘") #用户名 称呢
    password = models.CharField(max_length=20, default="123") #密码
    ip = models.CharField(max_length=20,  default="192.168.31.7")  #ip
    unReadMsgCount = models.IntegerField(default=0)  #未读信息 记数
    headicon = models.IntegerField(default=0) #头像
    time = models.CharField(max_length=20)  #时间
    ack = models.IntegerField(default=0)  #确认
    #数据库表名
    class Meta:
    	db_table = 'UserInfo'
    def __str__(self):
    	return self.macAddress


class MsgInfo(models.Model):
    headicon = models.IntegerField(default=0) #头像
    macAddress = models.CharField(max_length=20,  default="70720d06e84b")  #mac，发送人MacAddress
    name = models.CharField(max_length=20,  default="随缘") #发送人用户名 称呢
    mediaName = models.CharField(max_length=20,  default="") #语音留言文件名
    ip = models.CharField(max_length=20,  default="192.168.31.7")  #发送人ip
    personHeadicon = models.IntegerField(default=0)    
    personMacAddress = models.CharField(max_length=20,  default="94fe2271ac0c")
    personName = models.CharField(max_length=20,  default="天缘")
    personIp = models.CharField(max_length=20,  default="192.168.31.5") 
    msgContent = models.TextField() # 消息内容  
    unReadMsgCount = models.IntegerField(default=0)  #未读信息 记数
    successSign = models.CharField(max_length=8,  default="")  #发送接收成功标志
    time = models.CharField(max_length=20)  #发送时间
    #数据库表名
    class Meta:
    	db_table = 'MsgInfo'
    def __str__(self):
    	return self.macAddress

#Admin必须用 list_display
class UserInfoAdmin(admin.ModelAdmin):
	list_display = ('macAddress','name','password','ip','unReadMsgCount', 'headicon','time', 'ack')

class MsgInfoAdmin(admin.ModelAdmin):
    list_display = ('headicon','macAddress','name','ip','personHeadicon','personMacAddress','personName','personIp','msgContent','unReadMsgCount','successSign','time')

admin.site.register(UserInfo, UserInfoAdmin)#注册
admin.site.register(MsgInfo, MsgInfoAdmin)#注册
